<?php

namespace {

	// 确定本地主机和部署目录
	$g_SvrIp = $_SERVER["SERVER_ADDR"];
	$g_InLan =	('::1' == $g_SvrIp) || 
				('127.0.0.1' == $g_SvrIp) || 
				preg_match('/^192\.168\./', $g_SvrIp);
	define('i_LocHost', $g_InLan ? true : false);
	define('i_DploDiry', str_replace('\\', '/', dirname(__DIR__)) . '/');

	// 根据是否为本地主机确定WSE位置，引入
	$i_WseSeedDiry = i_DploDiry;
	$i_WseSeedDiry .= 'Wse/hpnWse/';
	require_once($i_WseSeedDiry . '(0)Seed.php');
	require_once($i_WseSeedDiry . 'HttpSvc.php');
	require_once($i_WseSeedDiry . 'nWp/(0)Base.php');

	// 错误处理
	@ini_set('log_errors', 'On');
	@ini_set('display_errors', 'Off');
	@ini_set('error_log', (i_DploDiry . 'PhpErr.log'));
	//throw new Exception("Error Processing Request", -2); // 测试日志

	// // 输出缓冲
	// ob_start();

	// 会话
	session_start();
}

namespace hpnApp {

// using
use \hpnWse\stStrUtil;
use \hpnWse\nWp\stBase as stWpBase;

	function fGetApiUrl()
	{
		return site_url() . '/api';
	}

	function fMakeApiUrl($a_Ctrl, $a_Actn)
	{
		if (!$a_Ctrl) { $a_Ctrl = 'index'; }
		return \hpnWse\fApdUrlQry(
			fGetApiUrl(),
			'_c=' . $a_Ctrl . '&_a=' . $a_Actn);
	}

	/// 包含片段模板
	function fIcldFgmtTmp($a_Flnm, $a_Once = false)
	{
		$l_Path = get_template_directory() . '/Tmp/' . $a_Flnm;
		if ($a_Once)
		{
			require_once($l_Path);
		}
		else
		{
			require($l_Path);
		}
	}

	function fGetAllSubjects()
	{
		$l_Subjects = stWpBase::cGetSubCtgrs(get_category_by_slug('subjects'));
		\hpnWse\stAryUtil::cSort($l_Subjects,
			function($a_S1, $a_S2)
			{
				return intval($a_S1->description) - intval($a_S2->description);
			});
		return $l_Subjects;
	}

	function fIsMember()
	{
		return isset($_SESSION['UserProfile']);
	}

	/// 作者名
	function fAthrName($a_Name)
	{
		return ('admin' == $a_Name) ? '中域集团' : $a_Name;
	}
}

//////////////////////////////////// OVER ////////////////////////////////////